﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BugZillaCrawler.UI
{
    class DataAnalyzer
    {
        public static void CalculateBugStateChangeTime(int bugId)
        {
            BugHistory[] bugHistories = DataAccess.Database.BugHistories.Where(h => h.BugId == bugId).ToArray<BugHistory>();

            // Calculate timespan between the state changes
            for (int i = 0; i < bugHistories.Length - 1; i++)
            {
                bugHistories[i].Age = (bugHistories[i + 1].When - bugHistories[i].When).TotalHours;
            }
        }

        public static void CalculateBugCommentResponseTime(int bugId)
        {
            BugComment[] comments = DataAccess.Database.BugComments.Where(c => c.BugId == bugId).ToArray<BugComment>();

            

            for (int i = 0; i < comments.Length-1; i++)
            {
                comments[i].ResponseTime = (comments[i + 1].Time - comments[i].Time).TotalHours;
            }
        }
    }
}
